home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 8 / Power CD-ROM 8.iso / prgmming / oldutil / upper.asm < prev    next >
Assembly Source File  |  1994-12-10  |  4KB  |  132 lines

  1.     Name upper
  2.     Title    Lowercase to Uppercase filter.
  3.     page    ,132
  4. comment /
  5.  
  6.     This program is a filter that translates all lowercase
  7.     characters to uppercase.  It will optionally accept a
  8.     filename to read input from.  All output goes to the
  9.     standard output device unless redirected.
  10.  
  11.     Examples:
  12.         Upper abc.txt        read input from abc.txt,
  13.                 output goes to screen.
  14.         Upper abc.txt >abcnew.txt
  15.                 read input from abc.txt,
  16.                 output goes to abcnew.txt.
  17.         Upper <abc.txt >abcnew.txt
  18.                 same as previous example
  19.         Upper abc.txt | find "ABC"
  20.                 translates abc.txt to uppercase
  21.                 and then searches the result
  22.                 for the string "ABC".
  23.                 Output goes to screen.
  24.         find "abc" abc.txt | upper | sort
  25.                               Search abc.txt for all lines that
  26.                 contain "abc".  Translate all lines
  27.                 selected and sort them, sending output
  28.                 to the screen.
  29. /
  30. ;===================================================================
  31. code    segment    public
  32. ;===================================================================
  33. ;
  34. ;    command line is at 80h of psp - first byte is length
  35. ;
  36.     org    80h
  37. parmsize    db    ?
  38. parm        db    7fh dup (?)
  39. ;
  40. ; .com starts at 100h - but must jump around any data area
  41. ;
  42.     org    100h            ; com file starts here
  43.     assume    cs:code,ds:code,es:code
  44. upper:
  45.     jmp    clear
  46. ;===================================================================
  47. ;
  48. ; data area for .com programs
  49. ;
  50. handle    dw    0h            ; assume standard input
  51. bufsiz    equ    256
  52. ;
  53. ;===================================================================
  54. clear:
  55. ;
  56. ; start of actual code is here (clear)
  57. ;
  58.     mov    ah,30h        ; get dos version
  59.     int    21h
  60.     cmp    al,2        ; must be at least 2.0
  61.     jb    oops
  62. ;
  63. ; release uneeded memory
  64. ;
  65.     mov    bx,offset buffer[512]    ; 256 byte buffer
  66.     mov    sp,bx            ; + 256 byte local stack
  67.     mov    cx,4
  68.     sar    bx,cl
  69.     inc    bx        ; paragraphs needed = end/16 + 1
  70.     mov    ah,4ah        ; SETBLOCK
  71.     int    21h
  72. ;
  73. ; now figure out which file to read from - parm line or standard input
  74. ;
  75.     cmp    parmsize,0h    ; if zero, no parm
  76.     jz    again        ; assume standard input
  77. ;
  78. ; parm length is not zero - assume the parm is a file name.  If not
  79. ; found, quit.
  80. ;
  81.     mov    al,parmsize    ; get size of parm
  82.     xor    ah,ah        ; zero out top part of accum.
  83.     mov    si,ax        ; use length as a pointer into the dta
  84.     mov    [si]+parm,0h    ; to tack on a zero byte (asciiz).
  85. ;
  86. ; now try to open the file
  87. ;
  88.     mov    dx,offset parm+1    ; address of 'filename'
  89.     mov    al,0h        ; open for read only
  90.     mov    ah,3dh        ; dos open function
  91.     int    21h        ; invoke function
  92.     jc    oops        ; open error - quit
  93.     mov    handle,ax    ; save file handle
  94. again:
  95.     mov    bx,handle    ; read from standard input or file
  96.     mov    cx,bufsiz    ; # of characters to read
  97.     mov    dx,offset buffer
  98.     mov    ah,3fh        ; dos read function
  99.     int    21h        ; invoke function
  100.     jc    oops        ; error!
  101.     cmp    ax,0h        ; if zero, end of file
  102.     jz    oops
  103. ;
  104.     push    ax        ; save copy of ax
  105.     mov    cx,ax        ; cx (and ax) contain # characters read
  106.     mov    si,offset buffer
  107.     mov    di,si        ; di gets it too
  108. loop1:
  109.     lodsb            ; get a character from buffer
  110.     cmp    al,'a'        ; if not between 'a' and 'z', skip
  111.     jl    ok
  112.     cmp    al,'z'
  113.     jg    ok
  114.     sub    al,20h        ; else switch to uppercase
  115. ok:
  116.     stosb            ; put back into buffer
  117.     loop    loop1        ; and repeat for entire buffer
  118. ;
  119.     pop    cx        ; restore character count
  120.     mov    bx,1h        ; standard output device
  121.     mov    ah,40h        ; dos write function
  122.     int    21h        ; invoke dos function
  123.  
  124.     jmp    again        ; repeat until end of file or error
  125. oops:
  126.     int    20h        ; return to dos
  127.  
  128. buffer    label    byte
  129.  
  130. code    ends
  131.     end    upper
  132.